//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "FdKlugeExtOUSpreadEngine.h"
using namespace Cephei::QL::Experimental::Finitedifferences;
#include <gen/QL/Experimental/Processes/KlugeExtOUProcess.h>
#include <gen/QL/Termstructures/YieldTermStructure.h>
#include <gen/QL/Methods/Finitedifferences/Solvers/FdmSchemeDesc.h>
#include <gen/QL/PricingEngine.h>
using namespace Cephei::QL::Experimental::Processes;
using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL::Methods::Finitedifferences::Solvers;
using namespace Cephei::QL;
#define HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Experimental::Finitedifferences::CFdKlugeExtOUSpreadEngine::CFdKlugeExtOUSpreadEngine (boost::shared_ptr<QuantLib::FdKlugeExtOUSpreadEngine>& childNative, Object^ owner) : CPricingEngine(CFdKlugeExtOUSpreadEngine::typeid)
{
#ifdef HANDLE
	_phFdKlugeExtOUSpreadEngine = NULL;
#endif
	_ppFdKlugeExtOUSpreadEngine = &childNative;
    _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdKlugeExtOUSpreadEngine));
}
Cephei::QL::Experimental::Finitedifferences::CFdKlugeExtOUSpreadEngine::CFdKlugeExtOUSpreadEngine (QuantLib::FdKlugeExtOUSpreadEngine& childNative, Object^ owner) : CPricingEngine(CFdKlugeExtOUSpreadEngine::typeid)
{
#ifdef HANDLE
	_phFdKlugeExtOUSpreadEngine = NULL;
#endif
	_ppFdKlugeExtOUSpreadEngine = new boost::shared_ptr<QuantLib::FdKlugeExtOUSpreadEngine> (&childNative);
    _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdKlugeExtOUSpreadEngine));
    _FdKlugeExtOUSpreadEngineOwner = owner;
    _PricingEngineOwner = owner;
}

Cephei::QL::Experimental::Finitedifferences::CFdKlugeExtOUSpreadEngine::CFdKlugeExtOUSpreadEngine (CFdKlugeExtOUSpreadEngine^ copy) : CPricingEngine(CFdKlugeExtOUSpreadEngine::typeid)
{
#ifdef HANDLE
	_phFdKlugeExtOUSpreadEngine = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppFdKlugeExtOUSpreadEngine = new boost::shared_ptr<QuantLib::FdKlugeExtOUSpreadEngine> (copy->GetShared());
        _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdKlugeExtOUSpreadEngine));
    }
}
Cephei::QL::Experimental::Finitedifferences::CFdKlugeExtOUSpreadEngine::CFdKlugeExtOUSpreadEngine (PLATFORM::Type^ t) : CPricingEngine(CFdKlugeExtOUSpreadEngine::typeid)
{
#ifdef HANDLE
	_phFdKlugeExtOUSpreadEngine = NULL;
#endif
	if (!t->IsSubclassOf(CFdKlugeExtOUSpreadEngine::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Finitedifferences::CFdKlugeExtOUSpreadEngine::CFdKlugeExtOUSpreadEngine (QuantLib::Handle<QuantLib::FdKlugeExtOUSpreadEngine>& childNative, Object^ owner)  : CPricingEngine(CFdKlugeExtOUSpreadEngine::typeid)
{
	_phFdKlugeExtOUSpreadEngine = &childNative;
	_ppFdKlugeExtOUSpreadEngine = &static_cast<boost::shared_ptr<QuantLib::FdKlugeExtOUSpreadEngine>>(childNative.currentLink());
    _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdKlugeExtOUSpreadEngine));
    _FdKlugeExtOUSpreadEngineOwner = owner;
}
Cephei::QL::Experimental::Finitedifferences::CFdKlugeExtOUSpreadEngine::CFdKlugeExtOUSpreadEngine (QuantLib::Handle<QuantLib::FdKlugeExtOUSpreadEngine> childNative)  : CPricingEngine(CFdKlugeExtOUSpreadEngine::typeid)
{
	_phFdKlugeExtOUSpreadEngine = &childNative;
	_ppFdKlugeExtOUSpreadEngine = &static_cast<boost::shared_ptr<QuantLib::FdKlugeExtOUSpreadEngine>>(childNative.currentLink());
    _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdKlugeExtOUSpreadEngine));
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Finitedifferences::CFdKlugeExtOUSpreadEngine::CFdKlugeExtOUSpreadEngine (QuantLib::FdKlugeExtOUSpreadEngine childNative)  : CPricingEngine(CFdKlugeExtOUSpreadEngine::typeid)
{
#ifdef HANDLE
	_phFdKlugeExtOUSpreadEngine = NULL;
#endif
	_ppFdKlugeExtOUSpreadEngine = new boost::shared_ptr<QuantLib::FdKlugeExtOUSpreadEngine> (new QuantLib::FdKlugeExtOUSpreadEngine (childNative));
    _ppPricingEngine = new boost::shared_ptr<QuantLib::PricingEngine> (boost::dynamic_pointer_cast<QuantLib::PricingEngine> (*_ppFdKlugeExtOUSpreadEngine));
}
#endif

Cephei::QL::Experimental::Finitedifferences::CFdKlugeExtOUSpreadEngine::~CFdKlugeExtOUSpreadEngine ()
{
    if (_ppFdKlugeExtOUSpreadEngine != NULL)
    {
	    delete _ppFdKlugeExtOUSpreadEngine;
        _ppFdKlugeExtOUSpreadEngine = NULL;
    }
}
Cephei::QL::Experimental::Finitedifferences::CFdKlugeExtOUSpreadEngine::!CFdKlugeExtOUSpreadEngine ()
{
    if (_ppFdKlugeExtOUSpreadEngine != NULL)
    {
	    delete _ppFdKlugeExtOUSpreadEngine;
    }
}
QuantLib::FdKlugeExtOUSpreadEngine& Cephei::QL::Experimental::Finitedifferences::CFdKlugeExtOUSpreadEngine::GetReference ()
{
    if (_ppFdKlugeExtOUSpreadEngine == NULL) throw REFNEW NativeNullException ();
	return **_ppFdKlugeExtOUSpreadEngine;
}
boost::shared_ptr<QuantLib::FdKlugeExtOUSpreadEngine>& Cephei::QL::Experimental::Finitedifferences::CFdKlugeExtOUSpreadEngine::GetShared ()
{
    if (_ppFdKlugeExtOUSpreadEngine == NULL) throw REFNEW NativeNullException ();
	return *_ppFdKlugeExtOUSpreadEngine;
}
QuantLib::FdKlugeExtOUSpreadEngine* Cephei::QL::Experimental::Finitedifferences::CFdKlugeExtOUSpreadEngine::GetPointer ()
{
    if (_ppFdKlugeExtOUSpreadEngine == NULL) throw REFNEW NativeNullException ();
	return &**_ppFdKlugeExtOUSpreadEngine;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::FdKlugeExtOUSpreadEngine>& Cephei::QL::Experimental::Finitedifferences::CFdKlugeExtOUSpreadEngine::GetHandle ()
{
	if (_phFdKlugeExtOUSpreadEngine == NULL)
	{
		_phFdKlugeExtOUSpreadEngine = new Handle<QuantLib::FdKlugeExtOUSpreadEngine> (*_ppFdKlugeExtOUSpreadEngine);
	}
	return *_phFdKlugeExtOUSpreadEngine;
}
#endif
bool Cephei::QL::Experimental::Finitedifferences::CFdKlugeExtOUSpreadEngine::HasNative () 
{
	return (_ppFdKlugeExtOUSpreadEngine != NULL);
}

Cephei::QL::Experimental::Finitedifferences::IFdKlugeExtOUSpreadEngine^ Cephei::QL::Experimental::Finitedifferences::CFdKlugeExtOUSpreadEngine::Calculate::get ()
{
    try
    {
    	(*_ppFdKlugeExtOUSpreadEngine)->calculate ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

